<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>角色管理</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../static/css/font.css">
<link rel="stylesheet" href="../../lib/layui/css/layui.css">
		<link rel="stylesheet" href="../../static/css/weadmin.css">
		<script src="../../lib/layui/layui.js" charset="utf-8"></script>
		<script src="../../static/js/app.js"></script>
		<script src="../../static/js/eleDel.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/js/common/optUtils.js"></script>
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
	      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
	    <![endif]-->
	</head>

	<body>
		<div class="weadmin-nav">
			<span class="layui-breadcrumb">
      </span>
			<a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
				<i class="layui-icon" style="line-height:30px">ဂ</i></a>
		</div>
		<div class="weadmin-body">
			<div class="layui-row">
				<form class="layui-form layui-col-md12 we-search" id="FirstForm">
					<div class="layui-inline">
						<input type="text" name="sysRoleName" placeholder="请输入角色名" autocomplete="off" class="layui-input">
					</div>
					<button class="layui-btn" lay-submit="" lay-filter="sreach" id="search1"><i class="layui-icon">&#xe615;</i></button>
				</form>
			</div>
			<div class="weadmin-block  demoTable">
				<button class="layui-btn" data-type="delBatch"><i class="layui-icon"></i>批量删除</button>
				<button class="layui-btn" data-type="addEle"><i class="layui-icon"></i>添加角色</button>
			</div>
			<table class="layui-table" id="maintable"  lay-filter="demo"></table>
		</div>
	</body>
	<script>
		var requrl=global.api_url + '/sysRole/selectAll'; //数据接口
		layui.use(['table','jquery','form'], function(){
			var table = layui.table,$=layui.jquery,form = layui.form;
			//第一个实例
			table.render({
				elem: '#maintable'
				,url:  requrl
				,id:'table1'
				,headers:{content_type: "application/json;charset=UTF-8",Authorization:getUser().token}
				,method:'post'
				,request: {
					pageName: 'current' //页码的参数名称，默认：page
					,limitName: 'size' //每页数据量的参数名，默认：limit
				}
				,parseData: function(res) { //res 即为原始返回的数据
					return {
						"code": res.code, //解析接口状态
						"msg": res.msg, //解析提示文本
						"count": res.data.total, //解析数据长度
						"data": res.data.records //解析数据列表
					}
				}
				,cols: [[ //表头
					{type:'checkbox'}
					,{field: 'sysRoleName', title: '角色名称'}
					,{field: 'descpt', title: '角色描述'}
					,{field: 'updateTime', title: '更新时间',templet:function (d) {
							return	dateToStr(d.insertTime);
						}}
					,{field: 'insertTime', title: '创建时间',templet:function (d) {
							return	dateToStr(d.insertTime);
						}
				}
					,{field:'', title:'操作', templet: '#barDemo', unresize: true}
				]]
				,page:true //开启分页
			});
			/**
			 * 提交查询条件后重新加载表格
			 */
			$('#search1').on('click', function(){
				var getForm = GetForm("FirstForm");
				//执行重载
				table.reload('table1', {
					page: {
						current: 1 //重新从第 1 页开始
					}
					, where: getForm
					, url:requrl//后台做模糊搜索接口路径
					, method: 'post'
				});
				return false;//false：阻止表单跳转  true：表单跳转
			});

			//监听工具条
			table.on('tool(demo)', function(obj){
				var data1 = obj.data;
				if(obj.event === 'del'){
					layer.confirm('真的删除行么', function(index){
						delBatch(data.id+",","/sysRole/delBatchByIds","table1");
						layer.close(index);
					});
				} else if(obj.event === 'edit'){
					//删除该表存储数据
					//给该表赋值
					sessionStorage.setItem("editRowData",JSON.stringify(data1));
					WeAdminShow('修改角色','./role-add.html?act=edit');
				}
			});

			var active = {
				delBatch: function(){ //获取选中数据
					var checkStatus = table.checkStatus('table1')
							,data = checkStatus.data;
					var ids="";
					for (var o in data){
						ids+=data[o].id+",";
					}
					delBatch(ids,"/sysRole/delBatchByIds","table1");
				}
				,addEle: function(){ //获取选中数目
					WeAdminShow('添加角色','./role-add.html?act=add');
				}
			};

			$('.demoTable .layui-btn').on('click', function(){
				var type = $(this).data('type');
				active[type] ? active[type].call(this) : '';
			});
		});
	</script>
	<script type="text/html" id="barDemo">
		<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	</script>
</html>